
/*
Written by Seung Il Moon (simoon@networking.khu.ac.kr)
 * 2011.01.04
 */

package net.m2m.policyeditor.view;

import net.m2m.policyeditor.controller.CreatePolicyEvent;
import net.m2m.policyeditor.model.PolicyListMnanager;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;


public class PEmakeShell {
	private PEmenuBar menuBar;
	private CreatePolicyForm createPolicyForm;
	private CreatePolicyEvent CrPolicyEvent;
	
	public PEmakeShell(PolicyListMnanager PCListManager) {		
		CrPolicyEvent = new CreatePolicyEvent(PCListManager, this);		
	}
	public Shell createShell(Display display) {
		// create shell 
		Shell shell = new Shell(display);
		shell.setText("M2M Condition");

		// get center point (x,y)
		Monitor primary = display.getPrimaryMonitor();
		Rectangle bounds = primary.getBounds();
		Rectangle rect = shell.getBounds();
		int x = bounds.x + (bounds.width - rect.width) / 2;
		int y = bounds.y + (bounds.height - rect.height) / 2;

		// set Location on center
		shell.setLocation(x, y);

		/**************************
			create MenuBar
		 **************************/
		menuBar = new PEmenuBar();
		menuBar.createMenuBar(shell);

		GridLayout gridLayout = new GridLayout();
		gridLayout.marginWidth = 15;
		gridLayout.marginHeight = 15;
		gridLayout.makeColumnsEqualWidth = true;
		shell.setLayout(gridLayout);

		/**************************
			create Table
		 **************************/
//		pTable = new PolicyTable();
//		pTable.createTable(shell);		
		
		createPolicyForm = new CreatePolicyForm();		
		createPolicyForm.CreatePolicyShell(shell);
		createPolicyForm.ButtonEvent(CrPolicyEvent.SelectEventBtCreate());
				
		
		/************************************
	 		M2M Network Configuration Form
		 ************************************/
//		networkConfigurationForm = new M2MNetworkConfigurationForm();
//		networkConfigurationForm.NetworkConfigurationForm(shell);
//		networkConfigurationForm.ButtonEvent(CrPolicyEvent.SelectEventBtCreate());		
					
		shell.pack();		
		return shell;
	}

	public PEmenuBar getMenuBar() {
		return menuBar;
	}
	
	public CreatePolicyForm getCreatePolicyForm() {
		return createPolicyForm;
	}	
		
}
